package com.cleaningcloud.erp.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cleaningcloud.common.log.annotation.Log;
import com.cleaningcloud.common.log.enums.BusinessType;
import com.cleaningcloud.common.security.annotation.RequiresPermissions;
import com.cleaningcloud.erp.domain.ErpCommodityType;
import com.cleaningcloud.erp.service.IErpCommodityTypeService;
import com.cleaningcloud.common.core.web.controller.BaseController;
import com.cleaningcloud.common.core.web.domain.AjaxResult;
import com.cleaningcloud.common.core.utils.poi.ExcelUtil;

/**
 * 商品类型管理Controller
 * 
 * @author cleaningcloud
 * @date 2024-09-26
 */
@RestController
@RequestMapping("/ErpCommodityType")
public class ErpCommodityTypeController extends BaseController
{
    @Autowired
    private IErpCommodityTypeService erpCommodityTypeService;

    /**
     * 查询商品类型管理列表
     */
    @RequiresPermissions("erp:ErpCommodityType:list")
    @GetMapping("/list")
    public AjaxResult list(ErpCommodityType erpCommodityType)
    {
        List<ErpCommodityType> list = erpCommodityTypeService.selectErpCommodityTypeList(erpCommodityType);
        return success(list);
    }

    /**
     * 导出商品类型管理列表
     */
    @RequiresPermissions("erp:ErpCommodityType:export")
    @Log(title = "商品类型管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ErpCommodityType erpCommodityType)
    {
        List<ErpCommodityType> list = erpCommodityTypeService.selectErpCommodityTypeList(erpCommodityType);
        ExcelUtil<ErpCommodityType> util = new ExcelUtil<ErpCommodityType>(ErpCommodityType.class);
        util.exportExcel(response, list, "商品类型管理数据");
    }

    /**
     * 获取商品类型管理详细信息
     */
    @RequiresPermissions("erp:ErpCommodityType:query")
    @GetMapping(value = "/{commodityTypeId}")
    public AjaxResult getInfo(@PathVariable("commodityTypeId") Long commodityTypeId)
    {
        return success(erpCommodityTypeService.selectErpCommodityTypeByCommodityTypeId(commodityTypeId));
    }

    /**
     * 新增商品类型管理
     */
    @RequiresPermissions("erp:ErpCommodityType:add")
    @Log(title = "商品类型管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ErpCommodityType erpCommodityType)
    {
        return toAjax(erpCommodityTypeService.insertErpCommodityType(erpCommodityType));
    }

    /**
     * 修改商品类型管理
     */
    @RequiresPermissions("erp:ErpCommodityType:edit")
    @Log(title = "商品类型管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ErpCommodityType erpCommodityType)
    {
        return toAjax(erpCommodityTypeService.updateErpCommodityType(erpCommodityType));
    }

    /**
     * 删除商品类型管理
     */
    @RequiresPermissions("erp:ErpCommodityType:remove")
    @Log(title = "商品类型管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{commodityTypeIds}")
    public AjaxResult remove(@PathVariable Long[] commodityTypeIds)
    {
        return toAjax(erpCommodityTypeService.deleteErpCommodityTypeByCommodityTypeIds(commodityTypeIds));
    }
}
